<?php
function GetUserNumId($u_nick){
global $app_key;
$paramArr = array(
'app_key'=>$app_key,
'method'=>'taobao.user.get',
'format'=>'xml',
'v'=>'2.0',
'timestamp'=>date('Y-m-d H:i:s'),
'fields'=>'user_id,buyer_credit',
'nick'=>$u_nick
);
$sign = createSign($paramArr);
$strParam = createStrParam($paramArr);
$strParam .= 'sign='.$sign;
$url = 'http://gw.api.taobao.com/router/rest?'.$strParam;
$result = vita_get_url_content($url);
$result = getXmlData($result);
return $result;
}
function GetTaoKeList($k,$c,$ep,$sp,$m,$p,$s,$p_size,$s_s="",$mall="")
{
global $app_key,$usernick;
$e_s="";
if(!empty($s_s))$e_s="5goldencrown";
$paramArr = array(
'app_key'=>$app_key,
'method'=>'taobao.taobaoke.items.get',
'format'=>'xml',
'v'=>'2.0',
'timestamp'=>date('Y-m-d H:i:s'),
'fields'=>'iid,num_iid,title,nick,pic_url,price,click_url,commission,item_location,volume,seller_credit_score,commission_rate',
'nick'=>$usernick,
'keyword'=>$k,
'sort'=>$s,
'cid'=>$c,
'page_no'=>$p,
'page_size'=>$p_size,
'outer_code'=>$m,
'end_price'=>$ep,
'start_price'=>$sp,
'start_credit'=>$s_s,
'end_credit'=>$e_s,
'mall_item'=>$mall
);
$sign = createSign($paramArr);
$strParam = createStrParam($paramArr);
$strParam .= 'sign='.$sign;
$url = 'http://gw.api.taobao.com/router/rest?'.$strParam;
$result = vita_get_url_content($url);
$result = getXmlData($result);
return $result;
}
function GetShop($k){
global $app_key;
$paramArr = array(
'app_key'=>$app_key,
'method'=>'taobao.shop.get',
'format'=>'xml',
'v'=>'2.0',
'timestamp'=>date('Y-m-d H:i:s'),
'fields'=>'sid,cid,pic_path,created,title,shop_score',
'nick'=>$k
);
$sign = createSign($paramArr);
$strParam = createStrParam($paramArr);
$strParam .= 'sign='.$sign;
$url = 'http://gw.api.taobao.com/router/rest?'.$strParam;
$result = vita_get_url_content($url);
$result = getXmlData($result);
return $result;
}
function ShopConvert($sid,$m){
global $app_key,$usernick;
$paramArr = array(
'app_key'=>$app_key,
'method'=>'taobao.taobaoke.shops.convert',
'format'=>'xml',
'v'=>'2.0',
'timestamp'=>date('Y-m-d H:i:s'),
'fields'=>'commission_rate,click_url',
'nick'=>$usernick,
'sids'=>$sid,
'outer_code'=>$m,
);
$sign = createSign($paramArr);
$strParam = createStrParam($paramArr);
$strParam .= 'sign='.$sign;
$url = 'http://gw.api.taobao.com/router/rest?'.$strParam;
$result = vita_get_url_content($url);
$result = getXmlData($result);
return $result;
}
function vita_get_url_content($url) {
$file_contents="";
if(function_exists('curl_exec')) {
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch,CURLOPT_URL,$url);
curl_setopt ($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$curl_code =0;
while($curl_code!=200) {
$file_contents = curl_exec($ch);
$curl_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
}
curl_close($ch);
}
elseif(function_exists('file_get_contents')) {
while(strlen($file_contents)==0){
$file_contents = file_get_contents($url);}
}
elseif(function_exists('fopen')){
$handle = fopen ($url,"rb");
do {
$data = fread($handle,8192);
if (strlen($data) == 0) {
break;
}
$$file_contents .= $data;
}while(true);
fclose ($handle);
}
return $file_contents;
}
function createSign ($paramArr) {
global $appSecret;
$sign = $appSecret;
ksort($paramArr);
foreach ($paramArr as $key =>$val) {
if ($key !=''&&$val !='') {
$sign .= $key.$val;
}
}
$sign = strtoupper(md5($sign));
return $sign;
}
function createStrParam ($paramArr) {
$strParam = '';
foreach ($paramArr as $key =>$val) {
if ($key != ''&&$val !='') {
$strParam .= $key.'='.urlencode($val).'&';
}
}
return $strParam;
}
function getXmlData ($strXml) {
$pos = strpos($strXml,'xml');
if ($pos) {
$xmlCode=simplexml_load_string($strXml,'SimpleXMLElement',LIBXML_NOCDATA);
$arrayCode=get_object_vars_final($xmlCode);
return $arrayCode ;
}else {
return '';
}
}
function get_object_vars_final($obj){
if(is_object($obj)){
$obj=get_object_vars($obj);
}
if(is_array($obj)){
foreach ($obj as $key=>$value){
$obj[$key]=get_object_vars_final($value);
}
}
return $obj;
}
function make_filehh($data,$file){
$fp=fopen($file,"w+");
$data=StripSlashes("$data");
fwrite($fp,"$data");
}
function createFolder($path)
{
if (!file_exists($path))
{
createFolder(dirname($path));
mkdir($path,0777);
}
}
function replacespecstr($specstr){
$pat = "/\*|\\\|\/|\:|\?|\"|\<|\>|\|/isU";
return preg_replace($pat," ",$specstr);
}
?> 
